Skip to content

feat: Add package flutter_gamepads#88

Merged
lea108 merged 66 commits intoflame-engine:mainfrom
lea108:feat/flutter-gamepads-package
Apr 3, 2026
Merged

feat: Add package flutter_gamepads#88
lea108 merged 66 commits intoflame-engine:mainfrom
lea108:feat/flutter-gamepads-package

Conversation

@lea108
Copy link
Copy Markdown
Collaborator

@lea108 lea108 commented Mar 28, 2026

Users can move focus, activate widgets and emit dismiss intents which closes alert dialogs for example.

Not all flutter widgets fully can be operated with the global intents. For example the Slider widgets uses private intents with additional support for keyboard shortcuts.

Background

The widget GamepadControl in this PR is based of a widget OverlayGamepadControl I wrote in a flame game. But it has been reworked to be more generic and apply not just for flame overlays but any widget trees.

In this work I now mainly focus on pure Flutter first, and then would like to look at Flame overlays to see what has to be done there in terms of focus management. I have now extended the example with a Flame game and provided documentation on how flutter_gamepads can be used for overlays in a Flame game. The core flutter_gamepads package still remains independent of Flame.

How to use it

Wrap your widgets with GamepadControl to allow users to navigate it using their gamepad.

GamepadControl(
    child: YourWidgets(),
)

Please do read the README.md for more in-depth info.

README.md
GamepadControl
GamepadInterceptor
Example

Todos

  • I am still not fully sure if I should use FocusScope.of(activateContext).previousFocus() or emit a PreviousFocusIntent().
  • Applying GamepadControl to parallell widget trees => doesn't really work. So recommendation is now to have GamepadControl in the root and then use GamepadInterceptor if you want to receive onBeforeIntent() locally.
  • Solve how to operate a ListView() without focusable elements with a gamepad => Tire 2 level support.
  • More elaborate app than then initial sample app which is mainly AI generated.
  • Key repeat support
  • Performance optimizations
    • I use abs() a bit in the logic which possible could be re-written as conditional logic with a slight performance gain?
    • ~~It currently maintain previousAxisValue for all axeses, not just those used in current shortcuts configuration.
    • IMHO the gain is too margin compared to lost readability in both cases, so I skipped them.
  • Finalize the default gamepad binding (shortcuts parameter)
  • Decide on final naming of parameters and widget names.
    • Use concept of Intents? Does the average Flutter developer know about the Intent system?

Tier 1, Tier 2

Tier 1

There likely will be a tier 1 level support of certain things that just work out of the box.

Tier 2

But there will likely be things like the Slider where users of this package need to do some manual wiring up to make it work.

For this the package provides GampadInterceptor() and onBeforeIntent callback. There are examples of implementing tire 2 level support in the example app.

lea108 added 2 commits March 28, 2026 11:54
…ased on gamepad input

Users can move focus, activate widgets and emit dismiss intents
which closes alert dialogs for example.

Not all flutter widgets fully can be operated with the global intents.
For example the Slider widgets uses private intents with additional
support for keyboard shortcuts.
@lea108 lea108 changed the title feat: add package flutter_gamepads feat: Add package flutter_gamepads Mar 28, 2026
lea108 added 11 commits March 28, 2026 12:55
Rewritten example to be human-based. More specifically the AI
had a Tab based control, but was still building the Bottom tabs
on each page.

The new example does trigger the issue that each page cannot have
a GamepadControl as when the settings page is pushed on the stack
the HomePage still remains and there would be duplicate focus
change intents.

I explored ways to handle that the gamepadControl of the page behind
would automatically disable itself, but it was hard to find a reliable
solution to that.

Instead I changed so there is just one GamepadControl at the top and
to be able to locally intercept the input you can use GamepadInterceptor
widget.
@lea108 lea108 marked this pull request as ready for review March 29, 2026 17:43
@lea108
Copy link
Copy Markdown
Collaborator Author

lea108 commented Mar 29, 2026

I'd love feedback on the name of especially the GamepadControl widget and also parameters in the API if something feels off.

For me GamepadControl feels 70-80% right, but not quite sure what would feel 100% right.

@lea108

This comment was marked as resolved.

@lea108 lea108 closed this Apr 2, 2026
@lea108 lea108 reopened this Apr 2, 2026
@lea108 lea108 merged commit 4f171c6 into flame-engine:main Apr 3, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant